CASE WHEN SQL Query executes condition in else even if first condition is true